package jdk8的特性.Stream.数值流;

import java.util.List;

import static jdk8的特性.Stream.数值流.MockFood.mockFoodList;

/**
 * @author idea
 * @data 2018/9/15
 */
public class TotalFoodCount {

    public int totalWeight;

    public int totalMoney;

    @Override
    public String toString() {
        return "TotalFoodCount{" +
                "totalWeight=" + totalWeight +
                ", totalMoney=" + totalMoney +
                '}';
    }

    public static void main(String[] args) {
        //食物总计 类
        TotalFoodCount tc=new TotalFoodCount();
        List<Food> foodList= mockFoodList();
        tc.totalWeight=foodList.stream()
                .map(Food::getWeight)
                .reduce(0,Integer::sum);

        tc.totalMoney=foodList.stream()
                .map(Food::getMoney)
                .reduce(0,Integer::sum);

        System.out.println(tc.toString());
    }
}
